home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / GRAPH.SWG / 0024_3DS.pas < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  11KB  |  362 lines

  1.                   3D Studio File Format  (3ds).
  2.                          Autodesk Ltd.
  3.  
  4.  
  5. Document Revision 0.8 -  December 1994.  First Public Release.
  6.  
  7. If you have any additions or comments to this file please e-mail me.
  8.  
  9. A lot of the chunks are still undocumented if you know what they
  10. do please email me.  As I get more information of the file format
  11. I will document it for everyone to see.  I will post this regularly
  12. to alt.3d and I can be contacted there if my email does not work.
  13.  
  14. Disclaimer.
  15. This document describes the file format of the 3ds files of 3D studio 
  16. by Autodesk.  By using the information contained within you agree not 
  17. to hold me liable if, from its use, you f^Hmuck something up. OK?  
  18.  
  19. Oh and just to make it clear I DO NOT work for Autodesk if you have
  20. any problems with their programs direct it to them not me!
  21.  
  22. Get to it!
  23.  
  24. Now with the joviality's aside all this info I have obtained with
  25. lots of work hacking at 3ds files with a diskeditor and diff.
  26. It has taken many months of hard work and piddling around with them 
  27. so I hope that it is appreciated.
  28.  
  29. Remember information wants to be free!
  30.  
  31. *  Jim Pitts.  -  18 December 1994
  32.  
  33. Contact me at jp5@ukc.ac.uk
  34.  
  35. 1.
  36.  
  37.   The 3ds file format is made up of chunks.  They describe what information 
  38.   is to follow and what it is made up of, its ID and the location of 
  39.   the next main block.  If you don't understand a chuck you can quite simply
  40.   skip it.  The next chunk pointer is relative to the start of the current 
  41.   chunk and in bytes.
  42.  
  43.   * A Chunk.
  44.  
  45.   start end  size  name
  46.   0     1    2     Chunk ID
  47.   2     5    4     Next Chunk
  48.  
  49.   Chunks have a hierarchy imposed on them that is identified by its ID.
  50.   A 3ds file has the Primary chunk ID 4D4Dh.  This is always the first chunk 
  51.   of the file.  With in the primary chunk are the main chunks.
  52.  
  53.   * Main Chunks
  54.  
  55.    id           Description
  56.  
  57.   3D3D          Start of object mesh data.
  58.   B000          Start of keyframer data.
  59.  
  60.   The Next Chunk pointer after the ID block points to the next Main chunk.
  61.  
  62.   Directly after a Main chunk is another chunk.  This could be any other
  63.   type of chunk allowable within its main chunks scope.
  64.  
  65.   For the Mesh description (3D3D) they could be any multiples of.
  66.  
  67.   * Subchunks of 3D3D. - Mesh Block
  68.  
  69.     id          Description
  70.    1100         unknown
  71.    1200         Background Colour.
  72.    1201         unknown
  73.    1300         unknown
  74.    1400         unknown
  75.    1420         unknown
  76.    1450         unknown
  77.    1500         unknown
  78.    2100         Ambient Colour Block
  79.    2200         fog?
  80.    2201         fog?
  81.    2210         fog?
  82.    2300         unknown
  83.    3000         unknown
  84.    4000         Object Block
  85.    7001         unknown
  86.    AFFF         unknown
  87.  
  88.    * Subchunks of 4000  - Object Description Block
  89.  
  90.    - first item of Subchunk 4000 is an ASCIIZ string of the objects name.
  91.  
  92.    Remember an object can be a mesh, a light or a camera.
  93.  
  94.     id          Description
  95.    4010         unknown
  96.    4012         shadow?
  97.    4100         Triangular Polygon Object
  98.    4600         Light
  99.    4700         Camera
  100.  
  101.  
  102.    * Subchunks of 4100 - Triangular Polygon Object
  103.  
  104.     id          Description
  105.    4110         Vertex List
  106.    4111         unknown
  107.    4120         Points List
  108.    4160         Translation Matrix
  109.  
  110.    * 4110 - Vertex List
  111.  
  112.    start end  size  type        name  
  113.     0     1    2    short int   Total vertices in object    
  114.  
  115.     2     5    4    float       X value
  116.     6     9    4    float       Y value
  117.    10    13    4    float       Z value
  118.    ..    ..    .     ..           ..
  119.    ..    ..    .     ..           ..
  120.  
  121.    bytes 2 .. 13 are repeated [Total vertices in object] times for 
  122.    each vertex.
  123.  
  124.    
  125.    * 4111 - unknown
  126.  
  127.    start end  size  type        name  
  128.     0     1    2    short int   Total vertices in object ?
  129.     
  130.     2     3    2    short int   unknown
  131.     .     .    .      ..          ..
  132.     .     .    .      ..          ..
  133.  
  134.     bytes 2..3 are repeated for X times as described by 
  135.     short int at start of record.
  136.  
  137.    
  138.    * 4120 - Points List
  139.  
  140.    start end  size  type        name  
  141.     0     1    2    short int   Total polygons in object - numpoly
  142.  
  143.     2     3    2    short int   Point 1
  144.     4     5    2    short int   Point 2
  145.     6     7    2    short int   Point 3
  146.     .     .    .     ..           ..
  147.     .     .    .     ..           ..
  148.  
  149.     Repeats 'numpoly' times for each polygon.
  150.     
  151.     
  152.     These points refer to the corresponding vertex of 
  153.     the triangular polygon from the vertex list.  
  154.     Points are organized in a clock-wise order.
  155.  
  156.  
  157.    * 4160 - Translation Matrix
  158.  
  159.     This structure describes a matrix for the object.
  160.     It is stored as a 3 X 4 matrix because it is assumed that
  161.     the right most column is 0,0,0,1 
  162.  
  163.    start end  size  type        name  
  164.     0     3    4    float       matrix 1,1
  165.     4     7    4    float       matrix 1,2
  166.     8    11    4    float       matrix 1,3
  167.    12    15    4    float       matrix 2,1
  168.    16    19    4    float       matrix 2,2
  169.    20    23    4    float       matrix 2,3
  170.    24    27    4    float       matrix 3,1
  171.    28    31    4    float       matrix 3,2
  172.    32    35    4    float       matrix 3,3
  173.    36    39    4    float       matrix 4,1
  174.    40    43    4    float       matrix 4,2
  175.    44    47    4    float       matrix 4,3
  176.  
  177.  
  178.    * 4600  - Light
  179.  
  180.  
  181.    start end  size  type        name  
  182.     0     3    4    float       Light pos X
  183.     4     7    4    float       Light pos Y
  184.     8    11    4    float       Light pos Z
  185.  
  186.     after this structure check for more chunks.
  187.  
  188.         id              Description    ( full description later )
  189.        0010             RGB colour
  190.        0011             24 bit Colour
  191.        4610             Spot light
  192.        4620             Light is off   (Boolean)
  193.        
  194.  
  195.    * 4610   -  Spot Light
  196.  
  197.  
  198.    start end  size  type        name  
  199.     0     3    4    float       Target pos X
  200.     4     7    4    float       Target pos Y
  201.     8    11    4    float       Target pos Z
  202.     12   15    4    float       Hotspot
  203.     16   19    4    float       Falloff
  204.  
  205.      
  206.    * 0010  - RGB colour
  207.  
  208.    start end  size  type        name  
  209.     0     3    4    float       Red
  210.     4     7    4    float       Green
  211.     8    11    4    float       Blue
  212.  
  213.  
  214.    * 0011  - RGB colour  -  24 bit
  215.  
  216.    start end  size  type        name  
  217.     0     0    1    byte        Red
  218.     1     1    1    byte        Green
  219.     2     2    1    byte        Blue
  220.       
  221.  
  222.    * 4700  - Camera
  223.  
  224.    Describes the details of a camera in the scene.
  225.  
  226.    start end  size  type        name  
  227.     0     3    4    float       Camera pos X
  228.     4     7    4    float       Camera pos Y
  229.     8    11    4    float       Camera pos Z
  230.     12   15    4    float       Target pos X
  231.     16   19    4    float       Target pos Y
  232.     20   23    4    float       Target pos Z
  233.     24   27    4    float       Camera Bank       
  234.     28   31    4    float       Camera Lens
  235.  
  236.    * 7001  - unknown chunk
  237.  
  238.    nothing known about this chunk except for its Subchunks.
  239.    This chunk also exists as a Subchunk in chunk B000 (keyframer info).
  240.  
  241.     id          Description
  242.    7011         unknown
  243.    7020         unknown
  244.  
  245.  
  246.    * B000   -  Keyframer Main chunk.
  247.  
  248.    Subchunks are
  249.  
  250.     id          Description
  251.    B00A         unknown
  252.    7001         unknown
  253.    B008         Frames  
  254.    B009         unknown
  255.    B002         Start object description
  256.  
  257.  
  258.    * B008   - Frame information
  259.  
  260.      simple structure describing frame info.
  261.  
  262.    start end  size  type        name  
  263.      0    3     4   integer     start frame
  264.      4    7     4   integer     end frame
  265.  
  266.  
  267.    * B002   - Start of Object info
  268.  
  269.      Subchunks
  270.  
  271.      id         Description
  272.     B010        Name & Hierarchy
  273.     B011*       Name Dummy object
  274.     B013        unknown
  275.     B014*       unknown
  276.     B015        unknown
  277.     B020        Objects pivot point?
  278.     B021        unknown
  279.     B022        unknown
  280.  
  281.  
  282.          ( * only on dummy objects )
  283.  
  284.    * B010   -  Name & hierarchy descriptor
  285.  
  286.    start end  size  type        name  
  287.      0    ?     ?   ASCIIZ      Object name
  288.      ?    ?     ?   short int   unknown
  289.      ?    ?     ?   short int   unknown
  290.      ?    ?     ?   short int   Hierarchy of object
  291.  
  292.      The object hierarchy is a bit complex but works like this.
  293.      Each object in the scene is given a number to identify its 
  294.      order in the tree.  Also each object is ordered in the 3ds 
  295.      file as it would appear in the tree.
  296.      The root object is given the number -1 (FFFF).
  297.      As the file is read a counter of the object number
  298.      is kept.
  299.      Is the counter increments the object are children of the previous
  300.      objects.  But when the pattern is broken by a number that will be
  301.      less than the current counter the hierarchy returns to that level.
  302.  
  303.      for example.
  304.  
  305.              object   hierarchy
  306.              name
  307.  
  308.                 A      -1
  309.                 B       0
  310.                 C       1                       This example is taken
  311.                 D       2                       from 50pman.3ds.
  312.                 E       1
  313.                 F       4                       I would really recommend
  314.                 G       5                       having a look at one of
  315.                 H       1                       the example with the
  316.                 I       7                       hierarchy numbers to help
  317.                 J       8                       work it out.
  318.                 K       0
  319.                 L      10
  320.                 M      11                       (if you can describe it
  321.                 N       0                        any better please let
  322.                 O      13                        me know. )
  323.                 P      14
  324.  
  325.  
  326.  
  327.  
  328.                                A
  329.            +-------------------+---------------+
  330.            B                   K               N
  331.        +---+---+               +               +
  332.        C   E   H               L               O
  333.        +   +   +               +               +
  334.        D   F   I               M               P
  335.            +   +
  336.            G   J
  337.  
  338.  
  339.  
  340.        Still not done with this chunk yet!
  341.  
  342.        If the object name is $$$DUMMY then it is a dummy object 
  343.        and therefore you should expect a few extra chunks.
  344.  
  345.  
  346.    *  B011   -  Dummy objects name.
  347.  
  348.         Names a dummy object. ASCIIZ string.
  349.  
  350.    *  B020  - Pivot Point?
  351.  
  352.    The objects pivot point.  Not quite sure what the first 
  353.    five floats do yet (ideas?).
  354.  
  355.    start end  size  type        name  
  356.      0    3     4   float       unknown    
  357.      4    7     4   float       unknown  
  358.      8   11     4   float       unknown    
  359.     12   15     4   float       unknown  
  360.     16   19     4  27     4   float       Pivot Y    
  361.     28   32     4   float       Pivot Z  
  362.